package com.lsq.baseadmin.modules.maintenance.config;

import com.lsq.baseadmin.modules.maintenance.entity.ScheduleJob;
import com.lsq.baseadmin.modules.maintenance.service.ScheduleJobService;
import com.lsq.baseadmin.modules.maintenance.utils.ScheduleUtils;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author lsq
 * @date 2020-11-07
 */
@Component
public class JobRunner implements ApplicationRunner {

    private final ScheduleJobService scheduleJobService;

    public JobRunner(ScheduleJobService scheduleJobService) {
        this.scheduleJobService = scheduleJobService;
    }

    /**
     * 项目启动时重新激活启用的定时任务
     * @param applicationArguments /
     */
    @Override
    public void run(ApplicationArguments applicationArguments){
        System.out.println("--------------------注入定时任务---------------------");

        List<ScheduleJob> list = scheduleJobService.list();
        list.forEach(ScheduleUtils::createScheduleJob);

        System.out.println("--------------------定时任务注入完成---------------------");
    }
}
